using UnityEngine;
using System.Collections;

public class create_char : MonoBehaviour {

	public GameObject Character;
	string namechar = "";
	public Transform Posicao;
	
	//public static Object prefab = Resources.Load("Prefab/character");
	
	
	void Start() {		
		Instantiate(Character, new Vector3(Posicao.position.x,Posicao.position.y,
										   Posicao.position.z), Quaternion.identity);	
		
	}
	void OnGUI() {
		namechar = GUI.TextField(new Rect(230, 350, 150, 30), namechar);
		if (GUI.Button (new Rect(255, 390,100,30),"Criar")){
			StartCoroutine(char_Create());					
		}
		
	}
	
	IEnumerator char_Create(){
		
		WWWForm form = new WWWForm();
		
		form.AddField("namechar", namechar);
		form.AddField("idLogin", constant_sistem.idUsuari_Atual);
						
		WWW webRequest = new WWW(constant_sistem.db_url + "character_create.php", form);
		
		yield return webRequest;
		
		if (webRequest.error !=null) {
			Debug.Log(webRequest.error);
		} else { 
			if(webRequest.text == "1") {
				Application.LoadLevel(2);;
			} else {
				Debug.Log("Erro ao criar");			
			}
		}
	}
	
}
